import { createRouter, createWebHashHistory } from 'vue-router'

const routes = [
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/Login.vue'),
    meta: { title: '登录', icon: 'User',isShow:false,layout:false },
  },
  {
    path: '/register',
    name: 'Register',
    component: () => import('@/views/Register.vue'),
    meta: { title: '注册', icon: 'User',isShow:false,layout:false },
  },
  {
    path: '/',
    component: () => import('@/components/layout/BasicLayout.vue'),
    name: 'BasicLayout',
    redirect: '/dashboard',
    meta: {
      title: import.meta.env.VITE_APP_TITLE,
      icon: 'HomeFilled',
      isShow:true,
      layout:true
  },
  children: [
    {
      path: '/dashboard',
      name: 'Dashboard',
      component: () => import('@/views/HomeView.vue'),
      meta: { title: '首页', icon: 'HomeFilled',isShow:true,layout:true }
    },
    {
      path: '/userinfo', 
      name: 'UserInfo',
      component: () => import('@/views/users/Userinfo.vue'),
      meta: { title: '个人信息', icon: 'User',isShow:false,layout:true },
    },
    {
      path: '/users',
      name: 'Users',
      component: () => import('@/components/layout/BasicLayout.vue'),
      meta: { title: '用户管理', icon: 'UserFilled',isShow:true,layout:true },
      redirect: '/users/detail/1',
      children: [
        {
          path: 'detail/:id', // 注意路径格式
          name: 'UserDetail',
          component: () => import('@/views/UserDetailView.vue'),
          meta: { title: 'User Detail',isShow:true,layout:true }
        },
        {
          path: 'external-link',
          name: 'ExternalLink',
          component: () => import('@/views/HomeView.vue'),
          meta: { 
            title: '外部链接', 
            isShow: true, 
            layout: true, 
            isExternal: true, 
            externalUrl: 'https://example.com' 
          },
        },
      ]
    },
    {
      path: '/settings',
      name: 'Settings',
      component: () => import('@/components/layout/BasicLayout.vue'),
      redirect: '/settings/profile',
      meta: { title: '系统设置', icon: 'Setting',isShow:true,layout:true },
      children: [
        {
          path: 'profile', // 注意路径格式
          name: 'SettingProfile',
          component: () => import('@/views/SettingProfileView.vue'),
          meta: { title: 'Profile',isShow:true,layout:true }
        },
        {
          path: 'security', // 注意路径格式
          name: 'SettingSecurity',
          component: () => import('@/views/SettingSecurityView.vue'),
          meta: { title: 'Security',isShow:true,layout:true }
        }
      ]
    }
  ]
  },
]

const router = createRouter({
  history: createWebHashHistory(),
  routes,
    //滚动行为
    scrollBehavior() {
      return {
          left: 0,
          top: 0,
      }
  },
})

export default router